package com.sky.api.client;

import com.sky.api.client.fallback.TradeFallbackFactory;
import com.sky.api.config.DefaultFeignConfig;
import com.sky.api.domain.dto.GoodsSalesDTO;
import com.sky.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author toki
 * openFeign,简化发送http请求的组件，在这里写跨服务的controller接口对应的API接口，并使用fallbackFactory进行降级处理
 */
@FeignClient(name = "trade-service",
    configuration = DefaultFeignConfig.class,
    fallbackFactory = TradeFallbackFactory.class)
public interface TradeFeignClient {

    @GetMapping("/admin/order/top10")
    Result<List<GoodsSalesDTO>> getSalesTop10(@RequestParam(name = "begin", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime begin,
                                              @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end);

    @GetMapping("/admin/order/turnoverStatistics")
    Result<Double> sumByMap(@RequestParam(name = "begin", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime begin,
                            @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end,
                            @RequestParam(name = "status", required = false) Integer status);

    @GetMapping("/admin/order/ordersStatistics")
    Result<Integer> countByMap(@RequestParam(name = "begin", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime begin,
                               @RequestParam(name = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end,
                               @RequestParam(name = "status", required = false) Integer status);
}